package vip.geeker.iotms.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import vip.geeker.iotms.dto.DeviceWarnInfoDto;
import vip.geeker.iotms.persistance.mapper.DeviceWarnInfoMapper;
import vip.geeker.iotms.persistance.mapper.WarnRuleMapper;
import vip.geeker.iotms.persistance.model.DeviceWarnInfo;
import vip.geeker.iotms.persistance.model.WarnRule;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
@Transactional
public class WarnService extends ServiceImpl<DeviceWarnInfoMapper, DeviceWarnInfo> {

    @Resource
    private DeviceWarnInfoMapper deviceWarnInfoMapper;
    @Resource
    private WarnRuleMapper warnRuleMapper;

    public PageInfo<DeviceWarnInfoDto> queryPage(DeviceWarnInfo warnInfo) {
        PageHelper.startPage(warnInfo.getPageNo(), warnInfo.getPageSz());
        List<DeviceWarnInfoDto> list = deviceWarnInfoMapper.queryDeviceWarnInfoDto(warnInfo);
        return new PageInfo<>(list);
    }

    public Boolean toAddWanRule(WarnRule rule) {
        rule.setCreateTime(new Date());
        return warnRuleMapper.insertSelective(rule) > 0;
    }

    public Boolean toDeleteWanRule(WarnRule rule) {
        return warnRuleMapper.deleteById(rule.getId()) > 0;
    }
}
